import { BaseWindow } from "../../../component/window/BaseWindow";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { GList } from "../../../../com/mui/controls/GList";
import { FishDropItemRenderer } from "./FishDropItemRenderer";
import { ScrollPolicy } from "../../../../fl/controls/ScrollPolicy";
import { ListEvent } from "../../../../fl/events/ListEvent";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { PageSelecter } from "../common/pageSelect/PageSelecter";
import { FishPickDef } from "./defin/FishPickDef";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ItemData } from "../../resource/info/ItemData";
type int = number;
//class FishDropItemWindow
    
    export  class FishDropItemWindow extends BaseWindow
    {
        constructor()
        {
            super();
            setSize(230, 500);
            title = Language.getString(41513);
            titleHeight = 25;
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(17, 38, 196, 420, this);
            this._list = new GList();
            this._list.styleName = "ScrollBarNormal";
            this._list.setStyle("skin", new Object /* flash.display.Bitmap */());
            this._list.setStyle("cellRenderer", FishDropItemRenderer);
            this._list.rowCount = 7;
            this._list.rowHeight = 53;
            this._list.setSize(182, 380);
            this._list.verticalScrollPolicy = ScrollPolicy.OFF;
            this._list.move(22, 40);
            this._list.addEventListener(ListEvent.ITEM_CLICK, this.onItemClickHandler);
            this._list.dataProvider = new DataProvider();
            this.addChild(this._list);
            this._pageSelecter = new PageSelecter();
            this._pageSelecter.x = 72;
            this._pageSelecter.y = 428;
            this.addChild(this._pageSelecter);
            var loc1=ObjCreate.createGButton(Language.getString(41516), 114, 463, 75, 25, this);
            this._pageSelecter.addEventListener(flash.events.Event.CHANGE, this.onPageChange);
            loc1.addEventListener(flash.events.MouseEvent.CLICK, this.onPickAllHandler);
            return;
        }

        /* internal  */onPageChange(arg1: Object /* flash.events.Event */): void
        {
            this.updateList();
            return;
        }

        /* internal  */onPickAllHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.pickAll();
            return;
        }

        /* internal  */pickAll(): void
        {
            var loc1=new FishPickDef();
            loc1.isPickAll = true;
            loc1.uid = "";
            Dispatcher.dispatchEvent(new DataEvent(EventName.FishPickItem, loc1));
            return;
        }

        /* internal  */onItemClickHandler(arg1: ListEvent): void
        {
            var loc1=new FishPickDef();
            loc1.isPickAll = false;
            loc1.uid = (arg1.item as ItemData).uid;
            Dispatcher.dispatchEvent(new DataEvent(EventName.FishPickItem, loc1));
            return;
        }

        public updateData(arg1: Array<any>): void
        {
            this._dataAry = arg1;
            this.updateList();
            return;
        }

        /* internal  */updateList(): void
        {
            this._pageSelecter.maxPage = Math.ceil(this._dataAry.length / this.PageSize);
            this._list.dataProvider = new DataProvider(this.getPageArray(this._pageSelecter.currentPage));
            return;
        }

        /* internal  */getPageArray(arg1: int): Array<any>
        {
            var loc1=new Array<any>();
            var loc2=(arg1 - 1) * this.PageSize;
            var loc3=arg1 * this.PageSize;
            loc2 = loc2 < 0 ? 0 : loc2;
            loc3 = loc3 > this._dataAry.length ? this._dataAry.length : loc3;
            var loc4=loc2;
            while (loc4 < loc3) 
            {
                loc1.push(this._dataAry[loc4]);
                ++loc4;
            }
            return loc1;
        }

        public static get instance(): FishDropItemWindow
        {
            if (!FishDropItemWindow._instance) 
            {
                FishDropItemWindow._instance = new FishDropItemWindow();
            }
            return FishDropItemWindow._instance;
        }

        /* internal */ /* const */PageSize: int=7;

        /* internal */ /* var */_list: GList;

        /* internal */ /* var */_pageSelecter: PageSelecter;

        /* internal */ /* var */_dataAry: Array<any>;

        /* internal */ static /* var */_instance: FishDropItemWindow;
    }
